/**************************************************************************************
*
*	Copyright (C) 2009 Brent Andrew Chua - See LICENSE.txt for more info.
*		
*	Filename	-	BitmapRot.h
*
*	Description -	Bitmap that supports rotation and masking.
*
*	Comments	-	* If you don't understand some part of the code, use MSDN!!!
*						Move the cursor to the function/type then hit F1 in VS.
*					* Sprite rotation is slow.... Avoid if possible.
*					* This doesn't support render blit options...
*					* The mask needs to be a seperate image.
*					
*
*	Modification History:
*			Name			   Date					Description
*			CodeSushi	-	11/18/2009	-	Creation of this file
**************************************************************************************/

#ifndef _BITMAP_ROTATION_H_
#define _BITMAP_ROTATION_H_

#include "Bitmap.h"

class BitmapRot : public Bitmap
{
public:
	
	BitmapRot( HINSTANCE hAppInst, const CHAR *pImageFileName, const CHAR *pImageMaskFileName = NULL, const PositionType posType = POS_UPPER_LEFT, const BlendOptions bOp = BLEND_SRC_COPY );
	virtual ~BitmapRot( void );

	// Uses degrees.
	void SetRotationDeg( FLOAT angle );
	FLOAT GetRotationDeg( void ) const;

	// Uses radians
	void SetRotationRad( FLOAT rad );
	FLOAT GetRotationRad( void ) const;

	void SetCenterRotation( INT x, INT y );
	void GetCenterRotation( INT &x, INT &y ) const;
	POINT GetCenterRotation( void ) const;

	virtual void Render( HDC hBBDC, HDC hSprDC, INT x, INT y );
	virtual void Render( HDC hBBDC, HDC hSprDC, INT x, INT y, INT w, INT h, INT srcX, INT srcY );
	//virtual void Render( HDC hBBDC, HDC hSprDC, RECT dest, INT srcX, INT srcY ); // Default one works

private:

	// We probably need this... just disable this for now.
	BitmapRot & operator = ( const BitmapRot &rhs );

	HBITMAP m_hBMMask;
	BITMAP	m_bMMInfo;
	FLOAT	m_rotRad;
	INT		m_xRot, m_yRot;
	POINT	m_polygon[3];
	//Pulse::BOOL m_createPoly;
};

PSX_INLINE BitmapRot::~BitmapRot( void )
{
	if ( m_hBMMask  )
		DeleteObject( m_hBMMask );
}

// Uses angles in degrees.
PSX_INLINE void BitmapRot::SetRotationDeg( FLOAT angle )
{
	if ( m_rotRad == PSX_DegToRad( angle ) )
		return;

	m_rotRad = PSX_DegToRad( angle );
	//m_createPoly = true;
}

PSX_INLINE FLOAT BitmapRot::GetRotationDeg( void ) const
{
	return PSX_RadToDeg( m_rotRad );
}

PSX_INLINE void BitmapRot::SetRotationRad( FLOAT rad )
{
	if ( m_rotRad = rad )
		return;

	m_rotRad = rad;
	//m_createPoly = true;
}

PSX_INLINE FLOAT BitmapRot::GetRotationRad( void ) const
{
	return m_rotRad;
}

PSX_INLINE void BitmapRot::SetCenterRotation( INT x, INT y )
{
	m_xRot = x; m_yRot = y;
}

PSX_INLINE void BitmapRot::GetCenterRotation( INT &x, INT &y ) const
{
	x = m_xRot;
	y = m_yRot;
}

PSX_INLINE POINT BitmapRot::GetCenterRotation( void ) const
{
	POINT pnt = { m_xRot, m_yRot };
	return pnt;
}

#endif /* _BITMAP_ROTATION_H_ */


